package com.blb.thread;


/**
 * 加入线程
 */
public class JoinDemo {

    static Thread thread1;
    static Thread thread2;

    public static void main(String[] args) {
            thread1 = new Thread(() -> {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "------>" + i);
                    if (i==5){
                        try {
                            thread2.join();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            });
            thread1.setName("张三");
            thread1.setPriority(5);
            thread2 = new Thread(() -> {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "------>" + i);
                    if (i==5){
                        try {
                            thread1.join();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            });
            thread2.setName("李四");
            thread2.setPriority(5);
            thread1.start();
            thread2.start();
    }



}
